package com.zretc.friend.mapper;


import com.zretc.api.pojo.User;
import com.zretc.friend.model.Friend;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface FriendMapper {

    @Select("SELECT * FROM Friend WHERE userId = #{userId} AND status = 'friend'")
    List<Friend> findByUserId(Integer userId);

    @Select("SELECT * FROM Friend WHERE userId = #{userId} AND status = 'blocked'")
    List<Friend> findByBlockedId(Integer userId);

    @Insert("INSERT INTO Friend(userId, friendId, status) VALUES(#{userId}, #{friendId}, #{status})")
    void addFriend(Friend friend);

    @Delete("DELETE FROM Friend WHERE userId = #{userId} AND friendId = #{friendId}")
    void deleteFriend(@Param("userId") Integer userId, @Param("friendId") Integer friendId);

    @Update("UPDATE Friend SET status = #{status} WHERE userId = #{userId} AND friendId = #{friendId}")
    void updateFriendStatus(@Param("userId") Integer userId, @Param("friendId") Integer friendId, @Param("status") String status);

    @Select("SELECT * FROM Friend WHERE userId = #{userId} AND friendId = #{friendId}")
    Friend findFriend(@Param("userId") Integer userId, @Param("friendId") Integer friendId);

    @Select("SELECT * FROM Friend WHERE userId = #{userId} AND status = 'following'")
    List<Friend> findFollowingByUserId(Integer userId);

    @Select("SELECT * FROM user WHERE user_id = #{userId}")
    User findUserById(Integer userId);
}

